C2 server and client v2 (with queues)

README

1. Make a basic UDP client and server

This section is meant to help you write the basic skeleton for a UDP client and server.

A UDP echo server is running at <IP>:5000. You may connect to it using nc -u <IP> 5000 to test your connectivity. It will echo back any message you send to it.

1.1. Client

Write a basic UDP socket client to connect to this server, send a message, read a response and print it to the screen.

Created with Raphaël 2.3.0terminalterminalclientclientserverserverhellohellohellohelloabcabcabcabc

1.2. Server

Write a similar echo server yourself. Test it using the client you wrote.

2. Command and control server and client

2.1. Make a heartbeat client

Write a UDP client that will send a heartbeat message to the server, and wait for a response from it, then sleep 1 second before the next heatbeat and repeat the process. Print the response to stdout. The heartbeat message sent has to be an integer picked up from stdin or the command line arguments (hereinafter called the “tag”). The response can be anything for now, though this will change in later parts.

# the message sent on each heartbeat will be "33"
$ ./client 8
Created with Raphaël 2.3.0clientclientserverserver8response1s delay8response1s delay8responseand so on...

2.2. Make a command dispatch server

Write a server that will accept commands from standard input and enqueue them. The input format should be <int tag> <command>. For example: 8 ls /home. The tag can be any integer from 0 to 16. Then when a client sends a heartbeat with a tag, reply with the earliest command with the same tag as a string. If no commands are in queue with that tag. The client is then expected to respond with the number 0, that the server reads and prints to the console.

Note: Clients may send heartbeats before you have inserted a command from the server terminal - in that case the server will send an empty message back and the client can skip doing anything and return 0
Note2: The server sends a non-empty message only once some command has been entered from the stdin, so it has to support taking in user input from the terminal even after starting to accept/handle the client.
Note3: Commands queued on the server with a tag that no client has yet sent, will remain in the server queue for that tag

Created with Raphaël 2.3.0terminal(server)terminal(server)serverserverclientclientterminal(client)terminal(client)0 ls /home1 rm /1rm /rm /1s delay1<empty><empty>2 id1 whoami1s delay1whoamiwhoami

2.3. Make a command executor client

Modify your previous echo client. It must still send a heartbeat like before, read the response from the server, and if it contains a command, execute it and send the exit code back to the server (instead of the fixed 0 that you were sending in 2.2). The server must print the exit code to its stdout

Created with Raphaël 2.3.0terminalterminalserverserverclientclientexecexec1responseempty responseno command to run1 ls /home1 rm /1s delay1ls /homels /home1 touch /tmp/aexit(0)001s delay1rm /rm /exit(1)111s delay1touch /tmp/atouch /tmp/aexit(0)001s delay1responseempty responseno command to run

2.4. Make a better command executor client and server

Extend the previous client and server. Make the client send not just the exit code, but also the contents of stdout and stderr to the server. The server must print this received stdout data to stdout and stderr data to stderr. It must print the exit code to stderr too.

Created with Raphaël 2.3.0stdinstdinstdoutstdoutstderrstderrserverserverclientclientexecexec3 ls /home /abc3ls /home /abcls /home /abcstdout("/home: ubuntu")stderr("ls: cannot access '/abc'...")exit(2)22ls: cannot access '/abc'.../home: ubuntu

2.5. Support multiple clients

Clients must be given tasks by the server in a first-come-first-served fashion.

Expand allBack to topGo to bottom